<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- <script>
        function Person(name, sex) {
            this.name = name;
            this.sex = sex;
        }
        // 添加方法
        Person.prototype.show = function() {
            console.log('this is show');
        }
        // 产生实例对象
        let xiaoming = new Person('xiaoming', 'nan');
        console.log(xiaoming);//erson {name: "xiaoming", sex: "nan"}
        xiaoming.show();//this is show
    </script> -->
    <script>
        // 定义类
        class Person {
            // 构造函数: 在实例化类的时候, 会自定触发
            // 在构造函数中设置的属性为对象所有,如果设置了方法,代表每一个对象都拥有相对应的方法
            constructor(name, sex) {
                this.naem = name;
                this.sex = sex;
            }
            // 向原型中添加方法
            show() {
                console.log('this is show');
            }
        }
        // 产生实例对象
        let xiaoming = new Person('xiaoming', 'nan');
        console.log(xiaoming);//Person {naem: "xiaoming", sex: "nan"}
        xiaoming.show();//this is show
    </script>
</body>
</html>